import { GetterTree } from 'vuex';
import { RootState } from "./types";

export type Getters = {
  // common
  menu(state: RootState): MenuItemVO[]
  // user
  roles(state: RootState): number[] | undefined
  userInfo(state: RootState): UserInfoVO | undefined
  accessToken(state: RootState): string | undefined
  refreshToken(state: RootState): string | undefined
  expiresIn(state: RootState): number | undefined
}


export const getters: GetterTree<RootState, RootState> & Getters = {
  menu: (state) => state.common.menu,
  roles: (state) => state.user.userInformation?.roles,
  userInfo: (state) => state.user.userInformation?.userInfo,
  accessToken: (state) => state.user.userToken?.access_token,
  refreshToken: (state) => state.user.userToken?.refresh_token,
  expiresIn: (state) => state.user.userToken?.expires_in,
}